#include"ObjectPool.h"
#include"ConCurrentAlloc.h"
#include"Common.h"
using std::cout;
using std::endl;

void alloc1()
{
	for (size_t i = 0; i < 5; i++)
	{
		void* ptr = ConCurrentAlloc(188);
	}
}

void alloc2()
{
	for (size_t i = 0; i < 5; i++)
	{
		void* ptr = ConCurrentAlloc(1);
	}
}

void TLS()
{
	std::thread t1(alloc1);
	t1.join();
	std::thread t2(alloc2);
	t2.join();
}

void TestConcurrentAlloc1()
{
	void* p1 = ConCurrentAlloc(6);
	void* p2 = ConCurrentAlloc(8);
	void* p3 = ConCurrentAlloc(1);
	void* p4 = ConCurrentAlloc(7);
	void* p5 = ConCurrentAlloc(8);

	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;
}

void MultiThreadAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = ConCurrentAlloc(6);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		ConcurrentFree(e, 6);
	}
}

void MultiThreadAlloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = ConCurrentAlloc(16);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		ConcurrentFree(e, 16);
	}
}

void TestMultiThread()
{
	std::thread t1(MultiThreadAlloc1);
	t1.join();
	std::thread t2(MultiThreadAlloc2);

	
	t2.join();
}
int main()
{
	//TestObjectPool();
	//TLS();

    //TestConcurrentAlloc1();
	TestMultiThread();
	return 0;
}